/* eslint-disable import/no-unresolved */
/* eslint-disable import/no-extraneous-dependencies */
/* eslint-disable @typescript-eslint/no-var-requires */
const FileManagerPlugin = require('filemanager-webpack-plugin');
const generateModifyVars = require('./build/generate/generateModifyVars');

const isMock = process.env.NODE_ENV === 'mock';

module.exports = {
  devServer: {
    port: isMock ? 8333 : 8444,
    proxy: {
      '^/node|^/api': {
        target: isMock ? '/' : '/',
        ws: true,
        changeOrigin: true,
      },
    },
  },
  configureWebpack: {
    devtool: process.env.NODE_ENV === 'production' ? 'hidden-source-map' : 'source-map',
    plugins: [
      new FileManagerPlugin({
        events: {
          onEnd: {
            copy: [{
              source: 'dist/**/*.map', destination: './map',
            }],
            delete: ['dist/**/*.map'],
          },
        },
      }),
    ],
  },
  pages: {
    index: {
      entry: 'src/main.ts',
      templace: 'public/index.html',
      filename: 'index.html',
    },
  },
  css: {
    loaderOptions: {
      less: {
        modifyVars: generateModifyVars(),
        javascriptEnabled: true,
      },
    },
    extract: true,
  },
};
